<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller {
    public function login(){

        if(IS_POST){
            $user = I('post.');
            if(!isset($user['username']) || !isset($user['pwd']) ){
                $this->error('用户名密码必填',U('admin/user/login'));
            }
            $find = M('user')->where(['username'=>$user['username']])->find();
            if(!$find){
                $this->error('用户名或密码错',U('admin/user/login'));
            }
            if(!password_verify($user['pwd'],$find['pwd'])){
                $this->error('用户名或密码错',U('admin/user/login'));
            }
            session('uid',$find['id']);
            
            $this->redirect('syndata/index');
        }
        $this->display();
    }


    public function logout(){
        session('uid',null);
        $this->redirect('user/login');
    }
}